package com.zhangyu.shadow.ec.main.personal.order;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.tepth.shadow.ui.recycler.MultipleField;
import com.tepth.shadow.ui.recycler.MultipleItemEntity;
import com.tepth.shadow.ui.recycler.MultipleRecyclerAdapter;
import com.tepth.shadow.ui.recycler.MultipleViewHolder;
import com.zhangyu.shadow.ec.R;

import java.util.List;

/**
 * @author zhangyu
 * @date 2018/1/4
 */

public class OrderListAdapter extends MultipleRecyclerAdapter {
    private static final RequestOptions REQUEST_OPTIONS =
            new RequestOptions().centerCrop()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .dontAnimate();

    protected OrderListAdapter(List<MultipleItemEntity> data) {
        super(data);
        addItemType(OrderListItemType.ITEM_ORDER_LIST, R.layout.item_order_list);
    }

    @Override
    protected void convert(MultipleViewHolder helper, MultipleItemEntity item) {
        super.convert(helper, item);
        helper.setText(R.id.tv_title, (CharSequence) item.getField(MultipleField.TITLE));
        helper.setText(R.id.tv_price, "价格:" + item.getField(OrderItemFields.PRICE));
        helper.setText(R.id.tv_time, "时间:" + item.getField(OrderItemFields.TIME));
        Glide.with(mContext)
                .load(item.getField(MultipleField.IMAGE_URL))
                .apply(REQUEST_OPTIONS)
                .into((ImageView) helper.getView(R.id.iv_thumb));
    }
}
